package com.itboy.controller;

import com.itboy.bean.Color;
import com.itboy.bean.User;
import com.itboy.mapper.ColorMapper;
import com.itboy.service.ColorService;
import com.itboy.service.UserService;
import tk.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.util.List;


/**
 * @Program: learnSpringBoot
 * @ClassName: com.itboy
 * @Author: Lee
 * @Copyright:Lee
 * @Date: 2021-01-09
 * @Description: ${todo}
 */
@RestController
public class  HelloController {

    @Qualifier("dataSource")
    @Autowired
    private DataSource dataSource;

    @Value("${itheima.url}")
    private String baidu;
    @Value("${baidu.url}")
    private String itheima;
    @GetMapping("hello")
    public String Hello(){
        //System.out.println( "dataSource"+dataSource);
        System.out.println( "baidu = "+baidu);
        System.out.println( "itheima = "+itheima);
        return "Hello，This is SpringBoot";
    }

    @Autowired
    private UserService userService;

    @GetMapping("/user/{id}")
    public User queryById(@PathVariable Integer id){
        return userService.queryById(id);
    }
    @Autowired
    private ColorService colorService;
    @GetMapping("/color")
    public List<Color> findAll(){
        return colorService.findAll();
    }
    @GetMapping("/color/{id}")
    public List<Color> findColorById(@PathVariable String id){
        return colorService.findColorById(id);
    }
    Color color;
    @GetMapping("/color/add")
    public void findColorById(Color color){
         color = new Color("8F0426AE-B90D-4065-9AB2-13DE5D7B0352","123","水壶","141","1");
         colorService.insertColor(color);
    }
    @GetMapping("/color/alter")
    public void alterById(Color color){
        color = new Color("8F0426AE-B90D-4065-9AB2-13DE5D7B0352","567","冰球","111141","1");
         colorService.alterById(color);
    }
    @GetMapping("/color/del/{id}")
    public void delById(@PathVariable String id){
         colorService.delById(id);
    }
}
